package com.baiytfp.hf.HFDataExchange.action.controller.service;

import com.baiytfp.hf.HFDataExchange.action.service.InterfaceService;
import com.baiytfp.hf.HFDataExchange.common.qzjdwebservice.*;
import com.baiytfp.hf.baiytfp.common.db.HFPager;
import com.baiytfp.hf.baiytfp.common.util.MD5Util;
import com.baiytfp.hf.baiytfp.framework.base.BaseController;
import com.baiytfp.hf.baiytfp.hfutils.HFRequest;
import com.baiytfp.hf.baiytfp.hfutils.HFResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/service/interface")
public class InterfaceSController extends BaseController {
    @Autowired
    private InterfaceService interfaceService;

    public final static String SYSCODE = "SYSCODE01";
    public final static String TICKET = "1F0284326CF7484985633842D6A0A823";

    /**
     * 主动接口
     * 根据检定机构获取对应的委托单信息接口
     *
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("getEntrustments")
    public void getEntrustments(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        long time = System.currentTimeMillis();
        String signData = MD5Util.MD5Encode(SYSCODE + TICKET + time, "utf-8");
        WsEntrustDocumentService wsEntrustDocumentService = new WsEntrustDocumentService();
        WsEntrustDocumentServiceI wsEntrustDocumentServiceI = wsEntrustDocumentService.getWsEntrustDocumentServicePort();
        EntrustDataResponse entrustDataResponse = null;
        try {
            entrustDataResponse = wsEntrustDocumentServiceI.getEntrustments(SYSCODE, signData, TICKET, time);
            List<WsApplyInstrumentInfo> wsApplyInstrumentInfoList = entrustDataResponse.getInstruments();
            List<WsEntrustDocument> WsEntrustDocumentList = entrustDataResponse.getEntrusts();
            WsApplyInstrumentInfo wsApplyInstrumentInfo = null;
            WsEntrustDocument wsEntrustDocument = null;
            //TODO 保存数据库
            HFResponse.getIstance().returnResult(response, 0, "", entrustDataResponse);
            System.out.println(entrustDataResponse.toString());
        } catch (IllegalAccessException_Exception e) {
            e.printStackTrace();
        } catch (InvocationTargetException_Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 接口列表
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("interfaceinfolist")
    public void interfaceInfoList(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HFPager hfPager = new HFPager(request);
        String interface_type = HFRequest.getIstance().getString(request, "interface_type");
        Map params = new HashMap();
        params.put("interface_type",interface_type);
        hfPager.setParams(params);
        List<Map> maps = interfaceService.listInterface(hfPager);
        HFResponse.getIstance().returnResult(response,hfPager.getResult());
    }


}
